package com.yuerlive.rainbow.module.game.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.entity.Gift;
import com.yuerlive.rainbow.utils.GlideUtil;
import com.yuerlive.rainbow.widget.RoundImageView;

import java.util.List;

import javax.net.ssl.CertPathTrustManagerParameters;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by xiaoyi on 2017/7/18.
 * 获胜弹框礼物列表
 */

public class WinerGiftAdapter extends BaseAdapter {
    List<Gift> gifts;
    Context context;


    public WinerGiftAdapter(Context context, List<Gift> gifts) {
        this.gifts = gifts;
        this.context = context;
    }

    @Override
    public int getCount() {
        return gifts.size();
    }

    @Override
    public Object getItem(int position) {
        return gifts.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_win_gift_item, parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Gift gift = gifts.get(position);
        holder.tvValue.setText(gift.getGiftRainbowSweet()+"");
        GlideUtil.load(context, gift.getIcon(), holder.ivIcon);
        if (gift.getChoosed() == 1){
            holder.ivIcon.setBackgroundResource(R.drawable.bg_gift_selected_dialog);
        }else {
            holder.ivIcon.setBackgroundResource(R.drawable.bg_gift_unselected_dialog);
        }
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.ivIcon)
        RoundImageView ivIcon;
        @BindView(R.id.tvValue)
        TextView tvValue;

        public ViewHolder(View itemView) {
            ButterKnife.bind(this, itemView);
        }
    }
}
